﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using BA2009.Web.Controllers;
using BA2009.Services;
using System.Web.Mvc;
using Moq;

namespace BA2009.Tests.Controllers
{
    [TestClass]
    public class BannerControllerTest
    {
        PagesController CreatePagesController()
        {
            var controller = new PagesController(new PageService(new Fakes.FakePageRepository(Fakes.FakeBA2009Data.CreateTestPages())));

            return controller;
        }

        BannersController CreateBannersController()
        { 
            var controller=new BannersController(new BannerService(new Fakes.FakeBannerRepository(Fakes.FakeBA2009Data.CreateTestBanners())));

            return controller;
        }

        [TestMethod]
        public void create_action_should_return_viewresult()
        {
            // Arrange
            var controller = CreateBannersController();
            // Act
            var result = controller.Create();

            // Assert
            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }

        [TestMethod]
        public void create_action_should_return_page_model()
        {
            // Arrange
            var controller = CreatePagesController();

            // Act
            ViewResult result = (ViewResult)controller.Create();

            // Assert
            Assert.IsInstanceOfType(result.ViewData.Model, typeof(BA2009.Entities.Page));
        }

        [TestMethod]
        public void create_action_with_new_page_should_return_view_and_repo_should_contain_new_page()
        {



            var mock = new Mock<ControllerContext>();

            var testData = Fakes.FakeBA2009Data.CreateTestBanners();
            var repository = new Fakes.FakeBannerRepository(testData);

            var service = new BannerService(repository);
            var controller = new BannersController(service);

            //var banner = Fakes.FakeBA2009Data.CreateBanner();

            ActionResult result = (ActionResult)controller.Create(Fakes.FakeBA2009Data.CreateBannerFormCollection());

            //Assert
            Assert.AreEqual(10, service.FindAll().Count);
            
            Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));
        }

    }
}
